package com.capinfo.service.impl;

import com.capinfo.base.BaseEntity;
import com.capinfo.base.BaseMapper;
import com.capinfo.base.impl.BaseServiceImpl;
import com.capinfo.entity.SysFileInfo;
import com.capinfo.entity.SysOffice;
import com.capinfo.mapper.SysFileInfoBatchMapper;
import com.capinfo.mapper.SysFileInfoMapper;
import com.capinfo.mapper.SysOfficeMapper;
import com.capinfo.service.SysFileInfoService;
import com.capinfo.util.JsonUtil;
import com.capinfo.utils.SysFileInfoBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: sunbenjin
 * @date: 2020/3/3
 **/
@Service
public class SysFileInfoServiceImpl extends BaseServiceImpl<SysFileInfo,String> implements SysFileInfoService {

    @Autowired
    SysFileInfoMapper sysFileInfoMapper;
    @Autowired
    SysFileInfoBatchMapper sysFileInfoBatchMapper;
    @Override
    public BaseMapper<SysFileInfo, String> getMappser() {
        return sysFileInfoMapper;
    }


    @Override
    public int insert(SysFileInfo record) {
        return super.insert(record);
    }

    @Override
    public int insertSelective(SysFileInfo record) {
        return super.insertSelective(record);
    }

    @Override
    public JsonUtil delById(String id, boolean flag) {
        JsonUtil j=new JsonUtil();

        try {
            SysFileInfo sysFileInfo = selectByPrimaryKey(id);
            if (flag) {
                //逻辑
                sysFileInfo.setDelFlag(BaseEntity.DEL_FLAG_DELETE);
                updateByPrimaryKeySelective(sysFileInfo);
            } else {
                //物理
                sysFileInfo.setDelFlag(BaseEntity.DEL_FLAG_DELETE);
                updateByPrimaryKeySelective(sysFileInfo);
//                sysOfficeMapper.delById(id);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg("删除成功");
        return null;
    }

    @Override
    public void updateBatchPrimaryKey(List<SysFileInfoBean> list) {
        List<List<SysFileInfoBean>> batchList = new ArrayList<>();
        batchList.add(list);
        batchList.forEach((data)->{
            sysFileInfoBatchMapper.updateBatchByPrimaryKeySelective(data);
        });
    }

    @Override
    public void batchUpdate(List<SysFileInfo> list) {
        sysFileInfoMapper.batchUpdate(list);
    }
}
